import { reqGetGoodsInfo ,reqAddOrUpdateShopCart} from "@/api";
import {getUUID} from '@/utils/uuid_token';
const state = {
    goodInfo:{},
    // 游客临时身份
    uuid_token:getUUID()
};
const mutations = {
    GETGOODINFO(state, GoodInfo) {
        state.goodInfo=GoodInfo;
    }
};
const actions = {
    async getGoodInfo({ commit }, skuid) {
        let result = await reqGetGoodsInfo(skuid);
        if (result.code == 200) {
            commit("GETGOODINFO", result.data)
        }
    },
    async reqAddOrUpdateShopCart({commit},{skuId,skuNum}){
        let result=await reqAddOrUpdateShopCart(skuId,skuNum);
        if(result.code==200){
            return "ok"
        }else{
            return Promise.reject(new Error('11111111111'));
        }
    },
};
// 简化数据
const getters = {
    // 路径导航
    categoryView(state){
        return state.goodInfo.categoryView||{};
    },
    // 产品信息
    skuInfo(state){
        return state.goodInfo.skuInfo||{};
    },
    // 产品售卖属性
    spuSaleAttrList(state){
        return state.goodInfo.spuSaleAttrList||[]
    },
};

export default {
    state, mutations, actions, getters
}